// Copyright 2007-2008 Helsinki Institute for Information Technology
// and the authors.
//
// Authors: Toni Ruottu <toni.ruottu@iki.fi>

// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

function saveindex()
{
    newcode = $F($("ihtml")).unescapeHTML();
    alert(newcode);
    HttpConnector.doPost('/content/public/web/index.html', newcode);
}

function doit()
{
	title=HttpConnector.doGet('/content/info/title.txt');
	putI("title",title)
    s=HttpConnector.doGet('/content')
    s = s.evalJSON(true)
    url = "http://" + s["parent"] + ".hexlabel.net/group/"

	code=HttpConnector.doGet('/content/public/web/index.html').escapeHTML();

putI("content","<h1 style=\"text-align: center;\">"+title+"</h1><p style=\"margin: 0 10%; text-align: justify;\"><em>"+title+"</em> is a Fusion application. Each Fusion application provides you with the tools for working on some specific type of data. Contact <a href=\""+url+"\">"+ title+" developer</a> for more information.<!--Visit some of the datasets from the list below, in order to see " +title+" at work.--></p><h2>Local Instances</h2><p style=\"margin: 1em 10%;\">"+title+" is used to display the following datasets of all datasets currently present on your system.</p><ul style=\"margin: 1em 13%;\"><li><a href=\"\">instance1</a></li><li><a href=\"\">instance2</a></li></ul><div style=\"text-align: center; margin: 1em 15%;\"><input type=\"button\" value=\"Create\" /> a new instance with title <input type=\"text\">  for <select><option>Joe Average</option><option>Knitting Club</option><option>Jazz Musicians Anonymous</option></select></div><h2>Integrated Development Environment</h2><p style=\"margin: 1em 10%;\">This user interface is available only to users who have rights required for changing the internal workings of an application. <strong>Please be careful!</strong> Changes made here have immediate effect for all user of the application at hand.</p><h3 style=\"margin: 1em 15% 0 15%;\">index.html</h3><div style=\"text-align: center;\"><textarea style=\"font-size: 1.5em; font-family: monospace; background-color: #000; color: #aaa;\"rows=\"20\" cols=\"80\" id=\"ihtml\"></textarea><br /> <input type=\"button\" value=\"save changes\" onClick=\"//saveindex()\"/></div><hr style=\"margin: 1.3em 10%;\" /><div style=\"text-align: center; margin: 1em 15%;\"><input type=\"button\" value=\"Create\" /> a new application with title <input type=\"text\">  for <select><option>Joe Average</option><option>Knitting Club</option><option>Jazz Musicians Anonymous</option></select></div>");
    putI("ihtml",code);

}

